home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / program / tsetguid.zip / TEA / SET / SAMPLE / GRAPHDEM.JAV < prev    next >
Text File  |  1997-02-27  |  3KB  |  91 lines

  1. /*
  2.  * Copyright (c) 1996-1997, InetSoft Technology Corp, All Rights Reserved.
  3.  *
  4.  * The software and information contained herein are copyrighted and 
  5.  * proprietary to InetSoft Technology Corp. This software is furnished 
  6.  * pursuant to a written license agreement and may be used, copied, 
  7.  * transmitted, and stored only in accordance with the terms of such 
  8.  * license and with the inclusion of the above copyright notice. Please 
  9.  * refer to the file "COPYRIGHT" for further copyright and licensing 
  10.  * information. This software and information or any other copies 
  11.  * thereof may not be provided or otherwise made available to any 
  12.  * other person. 
  13.  */
  14. package tea.set.sample;
  15.  
  16. import java.applet.*;
  17. import java.awt.*;
  18. import java.awt.event.*;
  19. import tea.set.*;
  20.  
  21. /**
  22.  * This is a demo applet to show using tea.set.Graph to build an
  23.  * interactive graph.
  24.  *
  25.  * @see Graph
  26.  * @version 1.3, 01/31/97
  27.  * @author InetSoft Technology Corp
  28.  */
  29. public class GraphDemo extends Applet {
  30.    public void init() {
  31.       setLayout(new BorderLayout());
  32.       
  33.       // create the dataset for the x axis
  34.       yx = new DataSet(false);
  35.       yx.setData(yearX);
  36.       mx = new DataSet(false);
  37.       mx.setData(monthX);
  38.       
  39.       add("North", title = new Label("Revenue (Million)"));
  40.       
  41.       // create the initial graph for yearly data
  42.       graph = new Graph(yx.getData(), (new DataSet(yearY)).getData());
  43.       add("Center", graph);
  44.       
  45.       graph.addItemListener(new GraphItemListener());
  46.       graph.addMouseListener(new GraphMouseListener());
  47.       
  48.       // display 3D bar chart
  49.       graph.setStyle(Graph.BAR3D);
  50.    }
  51.    
  52.    // drill down if clicked in a yearly chart, or return to yearly chart
  53.    // if currently displaying monthly data and mouse click is outside
  54.    // of chart area
  55.    class GraphItemListener implements ItemListener {
  56.       public void itemStateChanged(ItemEvent e) {
  57.      // drill down if in yearly chart and user clicked inside a bar
  58.      if(dsIdx == 0) {
  59.         Point p = (Point) e.getItem();
  60.         graph.setValues(mx.getData(), (new DataSet(y[p.x])).getData());
  61.         dsIdx = p.x + 1;
  62.      }
  63.       }
  64.    }
  65.    
  66.    class GraphMouseListener extends MouseAdapter {
  67.       public void mousePressed(MouseEvent e) {
  68.      // return to yearly chart if clicked outside of any bar
  69.      if(dsIdx != 0) {
  70.         dsIdx = 0;
  71.         graph.setValues(yx.getData(), (new DataSet(yearY)).getData());
  72.      }
  73.       }
  74.    }
  75.    
  76.    private Label title;
  77.    private Graph graph;
  78.    
  79.    private int dsIdx = 0;
  80.    private DataSet yx;
  81.    private DataSet mx;
  82.    
  83.    private String[] yearX = {"1994", "1995", "1996"};
  84.    private int yearY[] = {210, 244, 305};
  85.    private String[] monthX = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 
  86.                   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  87.    private int y[][] = { {12, 18, 15, 16, 8, 22, 25, 46, 8, 15, 11, 14},
  88.              {19, 18, 17, 16, 20, 22, 25, 36, 17, 25, 16, 13},
  89.              {29, 21, 19, 23, 15, 18, 33, 40, 52, 21, 11, 23} };
  90. }
  91.